
#include "etudiant.h"

//////////////////////////////etudiant////////////////////////////////////////////////////////////////


int Student::maxId= 0;




Semestre* Student::SelectSemestre(int num)
{
    if (num==0)
        return &semesterList.back();
    list<Semestre>::reverse_iterator rit;
    for (rit=semesterList.rbegin(); rit!=semesterList.rend(); ++rit)
    {
        if (rit->GetNumber() ==num)
            return &(*rit);
    }
}

void Student::AddSemester()
{
    int num;

    if (semesterList.empty())
    {
        num=1;
    }
    else
    {
        num = semesterList.back().GetNumber();
        num++;
    }

    Semestre s2(num);
    semesterList.push_back(s2);
}

void Student::RmSemester(int num)
{
    if (num==0)
    {
        semesterList.erase(--semesterList.end());
    }
    else
    {
        list<Semestre>::iterator it;
        for (it=semesterList.begin(); it!=semesterList.end(); ++it)
        {
            if (it->GetNumber() ==num)
            {
                semesterList.erase(it);
                break;
            }
        }
    }
}

//Affichage
void Student::Affiche(ostream &s)
{
    list<Semestre>::iterator it;
    s<<firstName << "   " << lastName <<"   " << branche << endl;

    for (it=semesterList.begin(); it!=semesterList.end(); ++it)
    {
        s << endl<< "--------------------------------" << endl;
        it->affiche(s);

    }
    s << endl<< "===========================================" << endl;

}



//////////////////////////////////SEMESTRE///////////////////////////////////////////////////////////


void Semestre::affiche(ostream &s)
{
    string periode;
    list<Uv>::iterator it;
    if (season==false) periode="d'Automne";
    else periode="de Printemps";
    s<<"semestre "<<number<< "  semestre " << periode <<endl;
    for (it=uvList.begin(); it!=uvList.end(); ++it)
        cout << " " << *it;
}


void Semestre::AddUv(string id)
{
    Uv newUv(id);
    list<Uv>::iterator it;
    if (uvList.size() >= 7) cout<<"trop d'uv"<<endl;
    else
    {
        for (it=uvList.begin(); it!=uvList.end(); ++it)
            if (it->GetCodeUv() == id)
            {
                cout << "UV deja ajoutee" << endl;
                return;
            }
        uvList.push_back (newUv);
    }
}

void Semestre::SetUv(string id, string note)
{
    list<Uv>::iterator it;
    for (it=uvList.begin(); it!=uvList.end(); ++it)
        if (it->GetCodeUv() == id)
        {
            it->SetResult(note);
            return;
        }
    cout << "UV absente de la liste" << endl;
}

void Semestre::RmvUv(string id)
{
    list<Uv>::iterator it;
    for (it=uvList.begin(); it!=uvList.end(); ++it)
        if (it->GetCodeUv() == id)
        {
            uvList.erase(it);
            return;
        }
    cout<< "UV inexistante dans la liste" << endl;
}



///////////////////////////////////UV//////////////////////////////////////////////////////////////////

ostream& operator<<(ostream &s, Uv &u)
{
    s << "UV: "<< u.GetCodeUv() << endl;
    if (u.GetResult() != "00")
        s << "Resultat: "<< u.GetResult() << endl<<endl;
    return s;
}

